package com.satan.novel.user.controller.front;

import com.satan.novel.book.dto.req.BookCommentReqDto;
import com.satan.novel.book.dto.req.UserCommentPageReqDto;
import com.satan.novel.book.dto.resp.UserCommentRespDto;
import com.satan.novel.common.auth.UserHolder;
import com.satan.novel.common.constant.ApiRouterConsts;
import com.satan.novel.common.constant.SystemConfigConsts;
import com.satan.novel.common.resp.PageRespDto;
import com.satan.novel.common.resp.RestResp;
import com.satan.novel.user.dto.req.UserInfoUptReqDto;
import com.satan.novel.user.dto.req.UserLoginReqDto;
import com.satan.novel.user.dto.req.UserPwdUptReqDto;
import com.satan.novel.user.dto.req.UserRegisterReqDto;
import com.satan.novel.user.dto.resp.UserInfoRespDto;
import com.satan.novel.user.dto.resp.UserLoginRespDto;
import com.satan.novel.user.dto.resp.UserRegisterRespDto;
import com.satan.novel.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FrontUserController
 * @Description 前台门户-会员模块 API 控制器
 * @date 2024/1/18 23:21
 * @Version 1.0
 */
@Tag(name = "FrontUserController", description = "前台门户-会员模块")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_USER_URL_PREFIX)
@RequiredArgsConstructor
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@Slf4j
public class FrontUserController {

    private final UserService userService;

    /**
     * 用户注册接口
     */
    @Operation(summary = "用户注册接口")
    @PostMapping("register")
    public RestResp<UserRegisterRespDto> register(@Valid @RequestBody UserRegisterReqDto dto) {
        return userService.register(dto);
    }

    /**
     * 用户登录接口
     */
    @Operation(summary = "用户登录接口")
    @PostMapping("login")
    public RestResp<UserLoginRespDto> login(@Valid @RequestBody UserLoginReqDto dto) {
        return userService.login(dto);
    }

    /**
     * 发表评论接口
     */
    @Operation(summary = "发表评论接口")
    @PostMapping("comment")
    public RestResp<Void> comment(@Valid @RequestBody BookCommentReqDto dto) {
        return userService.publishComment(dto);
    }

    /**
     * 修改评论接口
     */
    @Operation(summary = "修改评论接口")
    @PutMapping("comment/{id}")
    public RestResp<Void> updateComment(@Parameter(description = "评论ID") @PathVariable Long id,
                                        String content) {

        return userService.updateComment(id, content);
    }

    /**
     * 删除评论接口
     */
    @Operation(summary = "删除评论接口")
    @DeleteMapping("comment/{id}")
    public RestResp<Void> deleteComment(@Parameter(description = "评论ID") @PathVariable Long id) {
        return userService.deleteCommnet(id);
    }

    /**
     * 用户信息查询接口
     */
    @Operation(summary = "用户信息查询接口")
    @GetMapping
    public RestResp<UserInfoRespDto> getUserInfo() {
        return userService.getUserInfo(UserHolder.getUserId());
    }

    /**
     * 用户信息修改接口
     */
    @Operation(summary = "用户信息修改接口")
    @PutMapping
    public RestResp<Void> updateUserInfo(@Valid @RequestBody UserInfoUptReqDto dto) {

        return userService.updateUserInfo(dto);
    }

    /**
     * 用户密码修改接口
     */
    @Operation(summary = "用户密码修改接口")
    @PutMapping("password")
    public RestResp<Void> updateUserPwd(@Valid @RequestBody UserPwdUptReqDto dto) {
        return userService.updateUserPwd(dto);
    }

    @Operation(summary = "用户评论列表查询接口")
    @GetMapping("comments")
    public RestResp<PageRespDto<UserCommentRespDto>> listComments(@ParameterObject UserCommentPageReqDto dto) {
        return userService.listUserComments(dto);
    }

}
